package com.ysstech.etfmanage.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysstech.common.entity.PageBean;
import com.ysstech.etfmanage.entity.Skep;
import com.ysstech.etfmanage.mapper.SkepMapper;
import com.ysstech.etfmanage.service.SkepService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lishuangliang
 * @since 2021-02-25
 */
@Service
public class SkepServiceImpl extends ServiceImpl<SkepMapper, Skep> implements SkepService {
    /**
     * 查询ETF股票篮列表信息
     *
     * @param skep
     * @param pageBean
     * @return
     * @throws Exception
     */
    @Override
    public PageBean<Skep> queryAllEtfSkep(Skep skep, PageBean pageBean) throws Exception {
        QueryWrapper<Skep> wrapper = this.getQueryWrapper(skep);
        IPage<Skep> pageSkep = this.page(new Page<>(pageBean.getPageNum(), pageBean.getPageSize()), wrapper);
        this.switchedListEtfaccount(pageSkep.getRecords());
        return new PageBean<>(pageSkep);
    }

    /**
     * 类型等中文的转换
     *
     * @param list
     * @return
     * @throws Exception
     */
    public List<Skep> switchedListEtfaccount(List<Skep> list) throws Exception {
        for (Skep skep : list) {
            if (null == skep) {
                continue;
            }
        }
        return list;
    }

    /**
     * 查询条件
     *
     * @param skep
     * @return
     * @throws Exception
     */
    private QueryWrapper<Skep> getQueryWrapper(Skep skep) throws Exception {
        QueryWrapper<Skep> wrapper = new QueryWrapper<>();
        if (null == skep) {
            return wrapper;
        }
        if (StringUtils.isNotBlank(skep.getSelfdate())) {
            wrapper.eq("FDATE", skep.getSelfdate());
        }

        return wrapper;
    }
}
